/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

#include "LayerManager.h"

AnchorType_t Anchors[N_ANCHORS] = { 
	{GTK_ANCHOR_SW,  -8, -8},
	{GTK_ANCHOR_SOUTH, 0, -8},
	{GTK_ANCHOR_SE,   8, -8},
	{GTK_ANCHOR_NE,   8, 8},
	{GTK_ANCHOR_NORTH, 0, 8},
	{GTK_ANCHOR_NW,  -8, 8},
};


LayerManager::~LayerManager()
{
	// we didn't create this so don't delete them
	//gps_map = NULL;
	//layerG  = NULL;
}

LayerManager::LayerManager()
{
	gps_map = NULL;
	layerG  = NULL;
}

void LayerManager::init(GPSMap *map)
{
	gps_map = map;
	layerG  = NULL;
	isShown = false;
}

gboolean LayerManager::layer_timeout_cb(gpointer user_data)
{
	//cout << "LayerManager::updateMap - user_data=" << user_data << endl;

	LayerManager *me = (LayerManager *)user_data;
	if( !me )
		return false;

#ifdef USE_GDK_THREAD
	// GTK/GDK thread enter
	gdk_threads_enter();
#endif

	if( me->isShown )
		me->updateMap();
	
#ifdef USE_GDK_THREAD
	// GTK/GDK thread leave
	gdk_flush();
	gdk_threads_leave();
#endif

	return TRUE;
}

bool LayerManager::setShown(int setTo)
{	
	if(setTo == 0 || setTo == 1)
		isShown = setTo;
	else
		isShown ^= 1;

	if( !layerG ) return false;

	if( isShown )
		g_object_set (layerG,
				"visibility", GOO_CANVAS_ITEM_VISIBLE,
				NULL);
	else
		g_object_set (layerG,
				"visibility", GOO_CANVAS_ITEM_INVISIBLE,
				NULL);

	return isShown;
}


